You write custom CUDA kernels to replace PyTorch operators for speedups.
Implement LogSigmoid Affine Gate: For x[B,D], per-dim scale[D] and bias[D], compute z = x*scale + bias, gate g = logsigmoid(z) = -log(1+exp(-z)), and output y = x * g. Use a single grid-stride kernel to fuse affine, logsigmoid, and gating into one pass. Provide a PyTorch reference using nn.Parameters. Accuracy rtol=1e-3.
